//
//  TJStoreController.m
//  Teleport
//
//  Created by botu　 on 2020/7/31.
//  Copyright © 2020 byx. All rights reserved.
//

#import "TJStoreController.h"
#import "TJQuestionDetailController.h"
@interface TJStoreController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIButton *coimmitBtn;
@property (weak, nonatomic) IBOutlet UIView *nickBgView;
@property (weak, nonatomic) IBOutlet UIView *phoneBgView;
@property (weak, nonatomic) IBOutlet UIView *nameBgView;
@property (weak, nonatomic) IBOutlet UIView *cardBgView;
@property (weak, nonatomic) IBOutlet UITextField *nickTextField;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *cardLabel;
/**同意勾选按钮 */
@property (weak, nonatomic) IBOutlet UIButton *aggreBtn;

@end

@implementation TJStoreController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.backgroundColor = UIColor_Hex(0x2C6CC7);
    self.navigationBar.lineView.hidden = YES;
    
    self.navigationBar.titleTextColor = UIColor.whiteColor;
    self.navigationBar.title = @"商家申请".localizedString;
//    self.navigationBar.leftBarButton = [TJButtonBarButton barButtonBackButtonTarget:self action:@selector(popController)];
    [self.navigationBar backBarButtonWhiteColor];
    
    
    
    [self.nickBgView addRoundedLine];
    [self.phoneBgView addRoundedLine];
    [self.nameBgView addRoundedLine];
    [self.cardBgView addRoundedLine];
    
    
    
    
    self.nickTextField.delegate = self;
    
    self.phoneLabel.text = TJUserInfo.readInfo.phone;
    self.nameLabel.text = TJUserInfo.readInfo.uname;
    self.cardLabel.text =TJUserInfo.readInfo.cardNo;
    
}
/**提交 */
- (IBAction)commitBtnClick:(UIButton *)sender {
    
    if (!self.aggreBtn.selected) {
         [TJHud showAutoHideMessage:@"请同意《申请商户条款》".localizedString];
        return;
    }
    
    NSDictionary *parameters = @{
        @"userId": TJUserInfo.readInfo.userId,
        @"storeName": _nickTextField.text
    };
    
    [self showloading];
    weakify(self)
    [TJNetworking.shareNetworking POSTNew:@"member/member/setStore" parameters:parameters success:^(NSDictionary * _Nonnull responseObject, NSDictionary *data) {
        
        [weakself hiddenloading];
        [weakself.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError * _Nonnull error) {
        [weakself hiddenloading];
        [TJHud showAutoHideMessage:error.localizedFailureReason];
    }];
    
}

/**勾选 */
- (IBAction)aggreBtnClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    self.aggreBtn.selected = sender.selected;
   
}
/**服务条款 */
- (IBAction)clauseBtnClick {
    TJQuestionDetailController *detailVC  = [TJQuestionDetailController new];
    detailVC.type = 2;
    detailVC.navigationBar.title = @"申请商户条款".localizedString;
    [self.navigationController pushViewController:detailVC animated:YES];
}


-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(nonnull NSString *)string {
    
    NSUInteger length = textField.text.length - range.length + string.length;
    if (length > 0) {
        self.coimmitBtn.backgroundColor = UIColor.tj_mainColor;
        self.coimmitBtn.enabled = YES;
    }else{
        self.coimmitBtn.backgroundColor =UIColor_Hex(0xC6C6C8);
        self.coimmitBtn.enabled = NO;
    }
    
    
    return  YES;
    
}
//-(void)popController {
//    [self.navigationController popViewControllerAnimated:YES];
//}

//修改了模态方法 此方法不起作用
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
@end
